<?php
session_start();
if(isset($_SESSION['admin_id'])) {
    include "../include/dbFunctions.php";
    include "../include/formFunctions.php";
    include "../include/menu.php";
    $id = $_GET['id'];

// Data from volunteer table
    $query1 = "SELECT * FROM volunteer WHERE volunteer_id = $id";
    $volunteer_array = executeSelectQuery($query1);
    $salutation = $volunteer_array[0]['volunteer_salutation'];
    $gender = $volunteer_array[0]['volunteer_gender'];
    $status = $volunteer_array[0]['volunteer_status'];
    $email = $volunteer_array[0]['volunteer_email'];
    $office = $volunteer_array[0]['volunteer_office'];
    $mobile = $volunteer_array[0]['volunteer_mobile'];
    $sponsor_id = $volunteer_array[0]['sponsor_id'];

// Data from sponsor table
    if ($sponsor_id==null) {
        $sponsor = "Individual";
    } else {
        $query2 = "SELECT * FROM sponsor WHERE sponsor_id = $sponsor_id";
        $sponsor_array = executeSelectQuery($query2);
        $sponsor = $sponsor_array[0]['sponsor_name'];
    }
//Data from preferred educational level
    $msg = "";
    $query3 = "SELECT e.education_id, e.education_name
                FROM education e, education_preference p
                WHERE e.education_id = p.education_id
                AND p.volunteer_id = $id";
    $education_array = executeSelectQuery($query3);
    if ($education_array==null) {
        $msg = "This volunteer doesn't have any educational preference";
    }

//Data from trainer & event table
    $query5 = "SELECT *
                FROM event e, trainer t
                WHERE e.event_id = t.event_id
                AND t.volunteer_id = $id";
    $event_array = executeSelectQuery($query5);

//Data from sponsor table for select form
    $query6= "SELECT sponsor_id, sponsor_name FROM sponsor";
    $sponsor_array = executeSelectQuery($query6);

//Data from education table for select form
    $query7= "SELECT education_id, education_name FROM education";
    $education_array_original = executeSelectQuery($query7);

//Data from location table for select form
    $query8= "SELECT * FROM location";
    $location_array_original = executeSelectQuery($query8);

//Data from education_preference
    $query9= "SELECT * FROM location_preference WHERE volunteer_id=$id";
    $location_array = executeSelectQuery($query9);

//Data from available datetime
    $query10 = "SELECT * FROM time_preference WHERE volunteer_id='".$id."'";
    $timeslot_array  = executeSelectQuery($query10);
    if ((count($timeslot_array)==0)||(count($timeslot_array)==2)) {
        $status=2;
    } else {
        $status = ($timeslot_array[0]['time_id']);
    }
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JA Scheduling</title>

        <script type="text/javascript" language="javascript" src="../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/jquery/dataTable.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/jquery/jquery.validate.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/volunteerValidation.js"></script>

        <!--  CSS script -->
        <link rel="stylesheet" href="../media/css/screen.css" type="text/css" media="screen" title="default" />
        <link type="text/css" href="../media/css/dataTable.css" rel="stylesheet" />

        <!-- Manage table script -->
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#admintable').dataTable( {
                    "sPaginationType": "full_numbers"
                } );
                $("#volunteerform").validate(options_validate);
            } );
        </script>

    </head>
    <body>
        <!-- DON'T TOUCH! Start: page-top-outer -->
            <?php
            top_outer();
            ?>
        <!-- End: page-top-outer -->

        <div class="clear">&nbsp;</div>

        <!--  start nav-outer-repeat................................................................................................. START -->
        <div class="nav-outer-repeat">
            <!--  start nav-outer -->
            <div class="nav-outer">

                <!-- start nav-right -->
                    <?php
                    nav_right();
                    ?>
                <!-- end nav-right -->


                <!--  start nav -->
                <div class="nav">
                    <div class="table">
                            <?php
                            navigation_volunteer();
                            ?>


                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <!--  start nav -->

            </div>
            <div class="clear"></div>
            <!--  start nav-outer -->
        </div>
        <!--  start nav-outer-repeat................................................... END -->

        <div class="clear"></div>

        <!-- start content-outer ........................................................................................................................START -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">

                <!--  start page-heading --> <!--lyedit-->
                <div id="page-heading">
                    <h1>Edit Volunteer</h1>
                </div>
                <!-- end page-heading -->

                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table" >
                    <tr>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
                            <!--  start content-table-inner ...................................................................... START -->
                            <div id="content-table-inner">
                                <div id="table-content">
                                    <form action="action/volunteerDoUpdatePreference.php" method="post" id="volunteerform">
                                        <input type="hidden" name="id" value=<?php echo $id;?>></input>
                                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                            <input type="hidden" name="id" value=<?php echo $id;?>></input>
                                            <tr><th><h3>Preference</h3></th></tr>
                                            <tr>
                                                <th valign="top">Preferred<br/>Educational Level:</th>
                                                <td>
                                                        <?php
                                                        $default_array = getValueArray($education_array,"education_id");
                                                        $value_array = getValueArray($education_array_original,"education_id");
                                                        $display_array = getValueArray($education_array_original,"education_name");
                                                        dynamicCheckboxForm($default_array,$value_array,$display_array,"education[]")
                                                                ?>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Preferred Location:<INPUT type="button" value="" class="form-help" onClick="window.open('../include/singaporeArea.php','mywindow','width=520,height=340')"></th>
                                                <td>
                                                        <?php
                                                        $default_array = getValueArray($location_array,"location_id");
                                                        $value_array = getValueArray($location_array_original,"location_id");
                                                        $display_array = getValueArray($location_array_original,"location_name");
                                                        dynamicCheckboxForm($default_array,$value_array,$display_array,"location[]")
                                                                ?>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Preferred Day:</th>
                                                <td>
                                                    <select class="styledselect_form_1"  name="day">
                                                            <?php
                                                            $value_array = Array(2,0,1);
                                                            $display_array = Array('No Preference','Weekday','Weekend');
                                                            dynamicSelectForm($status,$value_array,$display_array);
                                                            ?>
                                                    </select>
                                                </td>
                                            </tr>
                                        </table>
                                        <input type="button" value="&nbsp" class="form-back" onClick="javascript:history.go(-1)"/>
                                        <input type="submit" value="&nbsp" class="form-save" />
                                        <input type="reset" value="&nbsp" class="form-cancel"  />
                                    </form>
                                </div>
                                <h2></h2>
                                <!--  start table-content  --> <!--lyedit-->
                                <div id="table-content">
                                    <!--  Can put table start from here within this div--> <!--lyedit-->

                                    <!--  end table-content here -->
                                </div>
                                <div class="clear"></div>
                            </div>
                            <!--  end content-table-inner ............................................END  -->
                        </td>
                        <td id="tbl-border-right"></td>
                    </tr>
                    <tr>
                        <th class="sized bottomleft"></th>
                        <td id="tbl-border-bottom">&nbsp;</td>
                        <th class="sized bottomright"></th>
                    </tr>
                </table>
                <div class="clear">&nbsp;</div>

            </div>
            <!--  end content -->
            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content-outer........................................................END -->
            <?php
            footer();
            ?>

    </body>
</html>
    <?php
}else {
    header("Location: ../include/login.html");
}
?>